import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'
// import { setupPageGuard } from './permission'
import LayoutAuthenticated from '@/layouts/LayoutAuthenticated.vue'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'root',
    component: LayoutAuthenticated,
    redirect: '/chat/home',
    children: [
      {
        path: '/chat/home',
        name: 'home',
        component: () => import('@/views/templates/HomeView.vue'),
      },
      // {
      //   path: '/chat/kg',
      //   name: 'kg',
      //   component: () => import('@/views/chat/KGChatView.vue'),
      // },
      {
        path: '/chat/basic',
        name: 'basic',
        component: () => import('@/views/chat/index.vue'),
      },
      {
        path: '/chat/pdf',
        name: 'PDFRoot',
        component: () => import('@/views/pdf/index.vue'),
      },
      {
        path: '/chat/extract_pdf',
        name: 'ExtractPdf',
        component: () => import('@/views/pdf/components/extract_detail/index.vue'),
      },
      {
        path: '/graphqa/chat',
        name: 'graphqa',
        component: () => import('@//views/GraphQA/index.vue'),
      },
      {
        path: '/chat/report',
        name: 'report',
        component: () => import('@//views/ReportChatView.vue'),
      },
      {
        path: '/chat/RAGreport',
        name: 'ragreport',
        component: () => import('@/views/RAG/RAGSearch.vue'),
      },
    ],
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404View.vue'),
  },

  {
    path: '/500',
    name: '500',
    component: () => import('@/views/500View.vue'),
  },

  {
    path: '/:pathMatch(.*)*',
    name: 'notFound',
    redirect: '/404',
  },
]

export const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior: () => ({ left: 0, top: 0 }),
})

// setupPageGuard(router)

export async function setupRouter(app: App) {
  app.use(router)
  await router.isReady()
}
